package com.hopu.controller;

import com.hopu.domain.UserInfo;
import com.hopu.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")

public class UserInfoController {

    @Autowired
    UserInfoService userInfoService;
    @RequestMapping("tologin")
    public String tologin(){
        return "login";
    }

    @RequestMapping("/home")
    public String logout(HttpSession session) {
        session.invalidate();
        return "/login";
    }

    /**
     * 主页面展示用户留言板
     *
     * @return
     */
    @RequestMapping("/main")
    public String main() {
        return "/home/olmsgList";
    }

    /**
     * 登陆成功后主页面	----三个模块
     *
     * @return
     */
    @RequestMapping("/fmain")
    public String fmain() {
        return "/home/fmain";
    }

    //主页顶部栏显示
    @RequestMapping("/title")
    public String title() {
        return "/home/title";
    }

    //主页左边栏显示
    @RequestMapping("/left")
    public String left() {
        return "/home/left";
    }

    /**
     * 货运管理页面跳转
     *
     * @return
     */
    @RequestMapping("/cargoMain")
    public String cargoMain() {
        return "cargo/main";
    }

    @RequestMapping("/cargoLeft")
    public String cargoLeft() {
        return "/cargo/left";
    }

    /**
     * 基础信息页面跳转
     *
     * @return
     */
    @RequestMapping("/baseinfoMain")
    public String baseinfoMain() {
        return "/baseinfo/main";
    }

    @RequestMapping("/baseinfoLeft")
    public String baseinfoLeft() {
        return "/baseinfo/left";
    }

    /**
     * 系统管理页面跳转
     *
     * @return
     */
    @RequestMapping("/sysadminMain")
    public String sysadminMain() {
        return "/sysadmin/main";
    }

    @RequestMapping("/sysadminLeft")
    public String sysadminLeft() {
        return "/sysadmin/left";
    }


    @RequestMapping("/login")
    public String login(HttpSession session, @RequestParam("userName") String userName, @RequestParam("passWord") String passWord){
        UserInfo userInfo = new UserInfo();
        userInfo.setUserName(userName);
        userInfo.setPassWord(passWord);
        UserInfo login = userInfoService.login(userInfo);
        if (login!=null){
            session.setAttribute("login", login);
            return "/home/fmain";
        }else {
             return "/login";
        }
    }
}
